﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Text;
using QTMusic.BaseClasses;

namespace QTMusic.Websites
{
    public partial class Default : System.Web.UI.Page
    {
        DataSet ds = new DataSet();

        protected void Page_Load(object sender, EventArgs e)
        {
            //Load cac bai hat moi nhat cho vao gridview
            string sqlCommand = null;

            sqlCommand = "SELECT s.song_id, s.song_name, a.artist_name, g.genre_name, su.songup_time, s.song_play_count, s.song_like_count, s.song_download_count  " +
                            "FROM   song AS s INNER JOIN " +
                            "artist AS a ON s.artist_id = a.artist_id INNER JOIN " +
                            "genre AS g ON s.genre_id = g.genre_id INNER JOIN " +
                            "songup AS su ON s.song_id = su.song_id " +
                            "ORDER BY su.songup_time DESC";

            SqlConnection conn = new SqlConnection(Common.connString);
            SqlCommand sql = new SqlCommand(sqlCommand, conn);

            //sql.Parameters.AddWithValue("@usname", e.Value);
 
            SqlDataAdapter sda = new SqlDataAdapter(sql);
            sda.Fill(ds, "NewSongs");

            if (ds.Tables["NewSongs"].Rows.Count != 0)
            {
                GridView1.DataSource = ds.Tables["NewSongs"];
                GridView1.DataBind();
            }
            conn.Close();   
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;

            GridView1.DataSource = ds.Tables["NewSongs"];
            GridView1.DataBind();
        }
    }
}